package com.example.bookstore.controller;

import com.example.bookstore.entity.User;
import com.example.bookstore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("login")
    @ResponseBody
    public String login(@RequestBody User user){

        String result = userService.userExsit(user);
        return result;
    }

    @PostMapping("add2")
    @ResponseBody
    public String insertUser(@RequestBody User user){

        userService.Insert(user);
        return "success";
    }

    @PostMapping("select")
    @ResponseBody
    public String selectUser(@RequestParam int id){

        String result = (userService.Select(id)).toString();
        return result;
    }

    @PostMapping("delete")
    @ResponseBody
    public String deleteUser(@RequestBody int id){

        userService.Delete(id);
        return "success";
    }

    @PostMapping("update")
    @ResponseBody
    public String updateUser(@RequestBody User user,@RequestParam int id){

        userService.Update(user,id);
        return "success";
    }

    @PostMapping("selects")
    @ResponseBody
    public String selectsUser(@RequestParam String thing, @RequestParam int id){
        return userService.Selects(thing,id);
    }

    @PostMapping("selectAll")
    @ResponseBody
    public ArrayList<User> selectAllUser(){
        return userService.selectAll();
    }
}
